package castle.defense.project;


/**
 * The Moveable class defines an object that has the ability
 * to move across the screen.  Associated with the each instance
 * is an image, a PhysicsPoint, an angle for direction of travel, and
 * a sound to be played upon the object's death.
 * 
 * @author KevinJoslyn
 *
 */
public abstract class Moveable extends Renderable implements Collidable {
	public int image;
	protected LinearPoint p;
	public float size;
	public int deathSound;
	public static float standardSize = 5;
	//private Paint paint;
	
	/**
	 * Moveable constructor without predefined LinearPoint
	 * 
	 * @param height	The Moveable object's height on the game screen
	 * @param image		The hash key of this object's image.
	 * @param x			The Moveable object's x coordinate (abstract units)
	 * @param y			The Moveable object's y coordinate (abstract units)
	 * @param speed		The Moveable object's speed
	 * @param angle		The angle representing the direction of travel
	 * @param size		The size of this object
	 * @param deathSound	The hash key of this object's death sound.
	 */
	public Moveable(int height, int image,double x, double y, double speed,  
			  double angle, float size, int deathSound) {
		
		//super(height);   To be added when MyDrawable is updated
		p = new LinearPoint(x,y,speed,angle);
		this.image = image;
		this.size = size;
		this.deathSound = deathSound;
	}
	
	/**
	 * Basic Moveable constructor.
	 * 
	 * @param height		The Moveable object's height on the game screen
	 * 
	 * @param image			The hash key of this object's image.
	 * @param p				The LinearPoint representing this object's movement in the game
	 * @param size			The size of this object
	 * @param deathSound	The hash key of this object's death sound.
	 */
	public Moveable(int height, int image, LinearPoint p, float size, int deathSound) {
		
		//super(height);  To be added when MyDrawable is updated
		this.image = image;
		this.p = p;
		this.size = size;
		this.deathSound = deathSound;
	}
	
	/**
	 * Asks whether the given Moveable object should be destroyed, or effectively
	 * removed from the screen.
	 * 
	 * @return True if the object should be removed from the screen,
	 * 		   False if the object should continue to be drawn.
	 */
	public boolean destroy() {
		return !PE.onScreen(p, size);
	}
	
	/**
	 * Updates the object's PhysicsPoint and hence the objects position
	 * on the screen.
	 * 
	 * @param milli
	 */
	public void update(long milli) {
		p.update(milli);
	}
	
	/**
	 * Tells the Soundmanager to play this object's death sound.
	 */
	public void makeDeathSound() {
		if(deathSound >= 0) {
			SoundManager.playSound(deathSound);
		}
	}
	
	/**
	 * Method defining what should happen when this object is to be destroyed.
	 * 
	 * @see destroy()
	 */
	public abstract void onDeath();
	
	public PhysicsPoint getPoint() {
		return p;
	}
	
	public double getX() { return p.getX();}
	public double getY() { return p.getY();}
	
	public float size() {
		return size;
	}
}
